package com.example.asus.yuejian_10.fragment;


<<<<<<< HEAD
import android.content.Context;
=======
>>>>>>> db13c3c4d7bee69c31cb0856f78c3871e5cea658
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
<<<<<<< HEAD
import android.widget.ImageView;
=======
>>>>>>> db13c3c4d7bee69c31cb0856f78c3871e5cea658
import android.widget.TextView;
import android.widget.Toast;

import com.example.asus.yuejian_10.Config;
import com.example.asus.yuejian_10.MainActivity;
import com.example.asus.yuejian_10.R;
import com.example.asus.yuejian_10.RetrofitSeveice;
<<<<<<< HEAD
import com.example.asus.yuejian_10.activity.OrderActivity;
import com.example.asus.yuejian_10.activity.SettingActivity;
=======
import com.example.asus.yuejian_10.activity.UserGuanZhuActivity;
import com.example.asus.yuejian_10.activity.UserShaiTuActivity;
>>>>>>> db13c3c4d7bee69c31cb0856f78c3871e5cea658
import com.example.asus.yuejian_10.base.BaseFragment;
import com.example.asus.yuejian_10.bean.User;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.asus.yuejian_10.Config.IMAGE_URL;


/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends BaseFragment {

    private TextView user_guanzhu;
    private TextView me_fatie;
    private RecyclerView user_shaitu_recyclerview;
    private RetrofitSeveice service;
    private String uid;
    private TextView me_sex;
    private TextView me_fans;
    private TextView me_setting;
    private TextView me_post;
    private TextView me_order;
    private TextView username;
    private TextView me_intro;
    private TextView me_focus;
    private CircleImageView me_pic;
    private Context context;

    public MeFragment() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Config.URL)
                .addConverterFactory(GsonConverterFactory.create()).build();
        service = retrofit.create(RetrofitSeveice.class);

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
<<<<<<< HEAD
        MainActivity mainActivity = new MainActivity();
        if(mainActivity!=null){
            uid = mainActivity.getUserId();
        }
        me_sex= (TextView) view.findViewById(R.id.me_sex);
        me_fans= (TextView) view.findViewById(R.id.me_fans);
        me_setting= (TextView) view.findViewById(R.id.me_setting);
        me_post= (TextView) view.findViewById(R.id.me_post);
        me_order= (TextView) view.findViewById(R.id.me_order);
        username= (TextView) view.findViewById(R.id.username);
        me_intro= (TextView) view.findViewById(R.id.me_intro);
        me_focus= (TextView) view.findViewById(R.id.me_focus);
        me_pic= (CircleImageView) view.findViewById(R.id.me_pic);

        Call<User> call = service.getuserinfo(Integer.parseInt(uid));

=======
        me_fatie=(TextView)view.findViewById(R.id.me_fatie);
        user_guanzhu=(TextView)view.findViewById(R.id.user_guanzhu);
//        user_shaitu_recyclerview=(RecyclerView)view.findViewById(R.id.user_shaitu_recyclerview);
        Call<User> call = service.user("2");
>>>>>>> db13c3c4d7bee69c31cb0856f78c3871e5cea658
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                User user = response.body();
                //Toast.makeText(getActivity(), user.getUser_name(), Toast.LENGTH_SHORT).show();
                if(user.getSex()!=null){
                    me_sex.setText(user.getSex());
                }
                else {
                    me_sex.setText("男");
                }

                me_fans.setText(user.getFocusnum());
                username.setText(user.getUser_name());
                if(user.getIntro()!=null){
                    me_intro.setText(user.getIntro());
                }
                else {
                    me_intro.setText("他很懒，什么也没写！");
                }


                if(user.getPhoto()!=null){
                    Picasso.with(context)
                            .load(IMAGE_URL+user.getPhoto())
                            .into(me_pic);
                }
                else {
                    me_pic.setImageResource(R.drawable.diagonallayout_hughjackman);
                }
            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {
                Toast.makeText(getActivity(), "联网失败！！！", Toast.LENGTH_SHORT).show();
            }
        });
        user_guanzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in=new Intent(getActivity(), UserGuanZhuActivity.class);
                startActivity(in);
            }
        });

      me_fatie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in=new Intent(getActivity(), UserShaiTuActivity.class);
                startActivity(in);
            }
        });

        me_setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SettingActivity.class);
                startActivity(intent);
            }
        });
        me_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), OrderActivity.class);
                startActivity(intent);
            }
        });
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_me, container, false);

    }

}
